/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */

package com.android.music.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.music.R;

public class HistoryAdapter extends BaseAdapter {

    private Cursor cursor;

    private Context mContext;

    public HistoryAdapter(Context context, Cursor cursor) {
        mContext = context;
        this.cursor = cursor;
    }

    public int getCount() {
        return cursor.getCount();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    private TextView lineItemName;

    private TextView duration;

    private TextView description;

    public View getView(int position, View convertView, ViewGroup parent) {
        cursor.moveToPosition(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.lineitem, null);
        }
        lineItemName = (TextView) convertView.findViewById(R.id.LineItemName);
        lineItemName.setText(String.valueOf(position + 1) + "、"
                + cursor.getString(1).substring(cursor.getString(1).lastIndexOf("/") + 1));
        duration = (TextView) convertView.findViewById(R.id.LineItemDuration);
        duration.setText(cursor.getString(2));
        description = (TextView) convertView.findViewById(R.id.LineItemDescription);
        description.setText(cursor.getString(3));
        if (position == cursor.getCount()) {
            cursor.close();
        }
        return convertView;
    }

}
